﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MongoHelper;
using MongodbHelper;
using MongoHelper.Model;
using System.IO;
using MongoDB.Driver.GridFS;
using MongoDB.Driver;
using MongoDB.Driver.Builders;

namespace Demo
{
    public partial class Form1 : Form
    {
        MongodbTool tool = new MongodbTool();
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            var list = new List<User>();
            for (int i = 0; i < 100; i++)
            {
                User user = new User();
                user.age = 20 + i;
                user.name = "测试" + i;
                list.Add(user);
            }
            //tool.Add(list);
            //tool.UpdateEntity<User>("name", "测试", "age", "99");
            //tool.DelEntity<User>("name","测试");
            long total = 0;
            IMongoQuery query = Query.And(
                Query.Matches("name", "1")
                );

            var ll = tool.FindMoreForPageByCondion<User>(query, 0, 10, ref total);
            var model = tool.FindAllMore<User>();

            string folder = @"E:\hgm\photo";
            DirectoryInfo di = new DirectoryInfo(folder);
            foreach (var file in di.GetFiles())
            {
                //tool.UploadFile(file.FullName, file.Name);
            }
            var fileModel = tool.FindAll().First();
            // 保存文件指定目录
            tool.DownloadFileOther("D:\\"+fileModel.Name, fileModel.Name);//下载文件到当前目录
            pictureBox1.ImageLocation = "D:\\"+fileModel.Name;
        }
    }
}
